package co.yixiang.huiMin.controller;


import co.yixiang.annotation.AnonymousAccess;
import co.yixiang.huiMin.dao.MachinistQueryCriteria;
import co.yixiang.huiMin.entity.PriceRange;
import co.yixiang.huiMin.entity.UserApply;
import co.yixiang.huiMin.service.PriceRangeService;
import co.yixiang.utils.PageUtil;
import co.yixiang.utils.QueryHelp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 价格区间 前端控制器
 * </p>
 *
 * @author Author
 * @since 2020-07-15
 */
@RestController
@RequestMapping("/priceRange")
@Api(tags = "金额管理")
public class PriceRangeController {

    @Resource
    private PriceRangeService priceRangeService;

    /**
     * 查询金额管理
     * @return
     */
    @AnonymousAccess
    @ApiOperation("查询金额管理")
    @GetMapping("/selectPriceRanges")
    public ResponseEntity<Object> selectPriceRanges(){
        List<PriceRange> list=priceRangeService.selectPriceRanges();
        HashMap<Object, Object> map = new HashMap<>();
        map.put("message", list);
        map.put("code",200);
        return new ResponseEntity<>(map, HttpStatus.OK);

    }


    /**
     * 根据id查询金额管理
     * @return
     */
    @AnonymousAccess
    @ApiOperation("根据id查询金额管理")
    @GetMapping("/selectPriceRangeById")
    public ResponseEntity<Object> selectPriceRangeById(String priceRangeId){
       PriceRange list=priceRangeService.selectPriceRangeById(priceRangeId);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("message", list);
        map.put("code",200);
        return new ResponseEntity<>(map, HttpStatus.OK);

    }

    /**
     *修改金额管理
     * @return
     */
    @AnonymousAccess
    @ApiOperation("修改金额管理")
    @PostMapping("/updatePriceRanges")
    public ResponseEntity<Object> updatePriceRanges(PriceRange priceRange) {

        HashMap<String, Object> stringObjectHashMap = new HashMap<>();

        int count=priceRangeService.updatePriceRanges(priceRange);
        if(count>0){
            stringObjectHashMap.put("code",200);
            return new ResponseEntity<>(stringObjectHashMap, HttpStatus.OK);
        }
        stringObjectHashMap.put("code",300);
        return new ResponseEntity<>(stringObjectHashMap, HttpStatus.OK);
    }


    /**
     *添加金额管理
     * @return
     */
    @AnonymousAccess
    @ApiOperation("添加金额管理")
    @PostMapping("/insertPriceRanges")
    public ResponseEntity<Object> insertPriceRanges(PriceRange priceRange) {

        HashMap<String, Object> stringObjectHashMap = new HashMap<>();

        int count=priceRangeService.insertPriceRanges(priceRange);
        if(count>0){
            stringObjectHashMap.put("code",200);
            return new ResponseEntity<>(stringObjectHashMap, HttpStatus.OK);
        }
        stringObjectHashMap.put("code",300);
        return new ResponseEntity<>(stringObjectHashMap, HttpStatus.OK);
    }

    /**
     *修改金额管理
     * @return
     */
    @AnonymousAccess
    @ApiOperation("删除金额管理")
    @PostMapping("/deletePriceRanges")
    public ResponseEntity<Object> deletePriceRanges(PriceRange priceRange) {

        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        priceRange.setIsDel(1);//是
        int count=priceRangeService.updatePriceRanges(priceRange);
        if(count>0){
            stringObjectHashMap.put("code",200);
            return new ResponseEntity<>(stringObjectHashMap, HttpStatus.OK);
        }
        stringObjectHashMap.put("code",300);
        return new ResponseEntity<>(stringObjectHashMap, HttpStatus.OK);
    }

    }

